package com.gzx.risk.app.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI customOpenAPI() {
        // 定义请求头参数 X-Self
        String headerName = "X-Self";
        Components components = new Components()
                .addSecuritySchemes(headerName,
                        new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY) // 类型：请求头参数
                                .in(SecurityScheme.In.HEADER) // 位置：请求头
                                .name(headerName) // 参数名：X-Self
                                .description("必须填写：gzx") // 提示信息
                );

        // 所有接口默认启用该请求头
        return new OpenAPI()
                .components(components)
                .addSecurityItem(new SecurityRequirement().addList(headerName));
    }
}